﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System;

namespace wsbank.cls
{
   
    class IniFile
    {
        string Path;

        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section, string key, string value, string filePath);

        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section, string key, string defaultValue, StringBuilder retVal, int size, string filePath);

        public IniFile(string INIPath)
        {
            Path = INIPath;
        }
        public void IniWriteValue(string Section, string Key, string Value)
        {
            WritePrivateProfileString(Section, Key, Value, Path);
        }

        public string IniReadValue(string Section, string Key)
        {
            var temp = new StringBuilder(255);
            int i = GetPrivateProfileString(Section, Key, "", temp, 255, Path);
            return temp.ToString();
        }


        
        public void readIni()
        {
            string value = IniReadValue("Section", "Key");
            Console.WriteLine(value); // 输出: Value
        }
        public void writeIni()
        {
            IniWriteValue("Section", "Key", "Value");
        }
        static void Main()
        {
            // 实例化IniFile类，并指定INI文件的路径
            IniFile ini = new IniFile("C:\\path\\to\\your\\file.ini");

            // 写入值
            ini.IniWriteValue("Section", "Key", "Value");

            // 读取值
            string value = ini.IniReadValue("Section", "Key");
            Console.WriteLine(value); // 输出: Value
        }
    }

}



